package prototype.demo2;

import java.io.*;

public class DeepTest {
    public static void main(String[] args) throws Exception {
        // 创建引用对象，并赋予值
        People people = new People();
        people.setName("xiangjiao");

        // 创建原型对象，并给其设定People类型值
        Realizetype2 realizetype2 = new Realizetype2();
        realizetype2.setPeople(people);

        // 创建输出流对象，将 Realizetype2 对象以流的形式保存至 文件中
        String path = System.getProperty("user.dir")+ File.separator+"src"+File.separator+ "prototype" +File.separator+"demo2"+File.separator+"a.txt";
        System.out.println("path-->"+path);
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path));
        // 将对象写入文件中
        oos.writeObject(realizetype2);
        // 释放流
        oos.close();

        // 从文件中读取流
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path));
        Realizetype2 clone2 = (Realizetype2) ois.readObject();
        ois.close();
        clone2.getPeople().setName("banana");

        System.out.println(realizetype2.getPeople().getName());
        System.out.println(clone2.getPeople().getName());

    }
}
